﻿
declare @typeId uniqueidentifier

select @typeId = '8A18ED50-3AD7-49C3-A13E-C187C756318A'

Select '
	if not exists(select typeId from [medianamik_HierarchicalRule] where TypeId = '''+cast(TypeId as varchar(38))+''' and ParentItemId = '''+cast(ParentItemId as varchar(38))+''')
	begin
		INSERT INTO [dbo].[medianamik_HierarchicalRule]
				   ([HierarchicalRuleId]
				   ,[TypeId]
				   ,[ParentItemId]
				   ,[ParentItemType])
			 VALUES
				   ('''+cast(HierarchicalRuleId as varchar(38))+'''
				   ,'''+cast(TypeId as varchar(38))+'''
				   ,'''+cast(ParentItemId as varchar(38))+'''
				   ,'+cast(ParentItemType as varchar(38))+')		
	end'
from [dbo].[medianamik_HierarchicalRule]
		where TypeId = @typeId
		
		